﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using BLL;
namespace 健身房管理
{
    public partial class UserGodsModify : Form
    { public int id=0;
        GoodsBLL gdl = new GoodsBLL();
        Point mouseOff;//鼠标移动位置变量
        bool leftFlag;//标签是否为左键

        private void UserGodsModify_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y);
                leftFlag = true;
            }
        }

        private void UserGodsModify_MouseMove(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);//设置移动后的位置
                Location = mouseSet;
            }
        }

        public UserGodsModify()
        {
            InitializeComponent();
        }

        private void guna2Button1_Click(object sender, EventArgs e)
        {
            
            string txtgoodname = txtgoods.Text;
            string goodstypes = goodstype.Text;
            int goodsnum = int.Parse(goodsnums.Text.ToString());
            int goodsprices = int.Parse(goodsprice.Text.ToString());
            string txtgoodsjts = txtgoodsjt.Text;
            string goodszhuant = guna2ComboBox1.Text;   //商品上架下架
            bool b1 = gdl.goodsModify(txtgoodname, goodstypes, goodsnum, goodsprices, txtgoodsjts, goodszhuant, id);
            if (b1)
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void guna2Button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void UserGodsModify_Load(object sender, EventArgs e)
        {
            jiaz();
        }
        public void jiaz()
        {

            DataTable dt = gdl.Modifyshow(id);
            if (dt.Rows.Count>0)
            {
                this.txtgoods.Text = dt.Rows[0]["goodsname"].ToString();
                this.goodstype.Text = dt.Rows[0]["goodstype"].ToString();
                this.goodsnums.Text = dt.Rows[0]["goodsnum"].ToString();
                this.goodsprice.Text = dt.Rows[0]["goodsprice"].ToString();
                this.txtgoodsjt.Text = dt.Rows[0]["goodsjtime"].ToString();
                this.guna2ComboBox1.Text = dt.Rows[0]["goodszhuangt"].ToString();
            }
        }

        private void UserGodsModify_MouseUp_1(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                leftFlag = false;//释放鼠标后标注为False
            }
        }

        private void UserGodsModify_MouseDown_1(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y);
                leftFlag = true;
            }
        }
    }
}
